package boot.service.impl.address;

import boot.dao.AddressMapper;
import boot.domain.address.Address;
import boot.domain.address.AddressExample;
import boot.domain.wxGoodsCart.GoodsShopcartExample;
import boot.service.addressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class addressServiceImpl implements addressService {
    @Autowired
    private  AddressMapper addressMapper;
    @Override
    public void addAddressByUserId(Address address) {
        addressMapper.insert(address);
    }
    @Override
    public List<Address> getAddressByUserId(int userId) {
        AddressExample addressExample = new AddressExample();
        AddressExample.Criteria criteria = addressExample.createCriteria();
        criteria.andUserIdEqualTo(userId);
        return addressMapper.selectByExample(addressExample);
    }

    @Override
    public void deleteAddressById(int id) {
        AddressExample addressExample = new AddressExample();
        AddressExample.Criteria criteria = addressExample.createCriteria();
        criteria.andIdEqualTo(id);
        addressMapper.deleteByExample(addressExample);
    }

    @Override
    public void editAddressByUserId(Address address, int id) {
        AddressExample addressExample = new AddressExample();
        AddressExample.Criteria criteria = addressExample.createCriteria();
        criteria.andIdEqualTo(id);
        addressMapper.updateByExampleSelective(address,addressExample);
    }
}
